package com.ruoyi.project.zerocarbon.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.zerocarbon.domain.DeclareImplementationPlan;
import com.ruoyi.project.zerocarbon.service.IDeclareImplementationPlanService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 项目实施情况及计划Controller
 * 
 * @author ruoyi
 * @date 2022-03-13
 */
@RestController
@RequestMapping("/zerocarbon/plan")
public class DeclareImplementationPlanController extends BaseController
{
    @Autowired
    private IDeclareImplementationPlanService declareImplementationPlanService;

    /**
     * 查询项目实施情况及计划列表
     */
    @PreAuthorize("@ss.hasPermi('zerocarbon:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeclareImplementationPlan declareImplementationPlan)
    {
        startPage();
        List<DeclareImplementationPlan> list = declareImplementationPlanService.selectDeclareImplementationPlanList(declareImplementationPlan);
        return getDataTable(list);
    }

    /**
     * 导出项目实施情况及计划列表
     */
    @PreAuthorize("@ss.hasPermi('zerocarbon:plan:export')")
    @Log(title = "项目实施情况及计划", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DeclareImplementationPlan declareImplementationPlan)
    {
        List<DeclareImplementationPlan> list = declareImplementationPlanService.selectDeclareImplementationPlanList(declareImplementationPlan);
        ExcelUtil<DeclareImplementationPlan> util = new ExcelUtil<DeclareImplementationPlan>(DeclareImplementationPlan.class);
        return util.exportExcel(list, "项目实施情况及计划数据");
    }

    /**
     * 获取项目实施情况及计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('zerocarbon:plan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(declareImplementationPlanService.selectDeclareImplementationPlanById(id));
    }

    /**
     * 新增项目实施情况及计划
     */
    @PreAuthorize("@ss.hasPermi('zerocarbon:plan:add')")
    @Log(title = "项目实施情况及计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeclareImplementationPlan declareImplementationPlan)
    {
        return toAjax(declareImplementationPlanService.insertDeclareImplementationPlan(declareImplementationPlan));
    }

    /**
     * 修改项目实施情况及计划
     */
    @PreAuthorize("@ss.hasPermi('zerocarbon:plan:edit')")
    @Log(title = "项目实施情况及计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeclareImplementationPlan declareImplementationPlan)
    {
        return toAjax(declareImplementationPlanService.updateDeclareImplementationPlan(declareImplementationPlan));
    }

    /**
     * 删除项目实施情况及计划
     */
    @PreAuthorize("@ss.hasPermi('zerocarbon:plan:remove')")
    @Log(title = "项目实施情况及计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(declareImplementationPlanService.deleteDeclareImplementationPlanByIds(ids));
    }
}
